package com.qf.shop.service.Impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qf.shop.entity.Cart;
import com.qf.shop.entity.User;
import com.qf.shop.mapper.UserMapper;
import com.qf.shop.model.TableData;
import com.qf.shop.pojo.QueryUser;
import com.qf.shop.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @ Author     ：lzq.
 * @ Date       ：Created in 9:45 2020/10/21
 */
@Service
@Transactional
public class UserServiceImpl implements IUserService {
    private UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public TableData<User> getPageData(QueryUser queryUser, int offset, int limit) {
        String name = queryUser.getName();
        if (null != name && !"".equals(name.trim())) {
            queryUser.setName("%" + name + "%");
        }

        Page<User> page = PageHelper.offsetPage(offset, limit);
        userMapper.getPageData(queryUser);
        TableData<User> tableData = new TableData<>();
        tableData.setRows(page.getResult());
        tableData.setTotal(page.getTotal());
        return tableData;
    }

    @Override
    public void activeUserId(Integer id) {
       userMapper.activeUserId(id);
    }

    @Override
    public void banUserId(Integer id) {
        userMapper.banUserId(id);
    }

    @Override
    public List<User> getData(QueryUser queryUser) {
        String name = queryUser.getName();
        if(null != name && !"".equals(name.trim())) {
            queryUser.setName("%" + name + "%");
        }
        List<User> userList = userMapper.getData(queryUser);
        return userList;
    }

    @Override
    public void batchInset(List<User> userList) {
        userMapper.batchInset(userList);
    }


}
